fn main() {
    // let Some(x) = plus_one_f(Some(5));//错误，Some(5)是一个Option<i32>类型
    if let Some(x) = plus_one_f(Some(5)) {
        println!("The value of x is {}", x);
    }

    let y = plus_one(None);
    
println!("The value of y is {}", y);
// for 循环
let v = vec!['a', 'b', 'c'];
for element in v {
    println!("{}", element);
}
// while 循环
let mut counter = 0;
while counter != 10 {
    println!("{}!", counter);
    counter += 1;
}
println!("LIFTOFF!!!");

let x = Some(5);
    let y = 10;
    match x {
        Some(50) => println!("five"),
        Some(y) => println!("matche y={}", y),
        _ => println!("something else"),
    }
    println!("at the end: x={:?}, y={}", x, y);

    let msg = Message::ChangeColor(0, 160, 255);
    match msg {
        
        Message::Quit => {
            println!("The Quit variant has no data to destructure.");
        },
        Message::Move { x, y } => {
            println!("Move in the x direction {} and in the y direction {}", x, y);
        }
        Message::Write(text) => println!("Text message: {}", text),
        Message::ChangeColor(r, g, b) => {
            println!("Change the color to red {}, green {}, and blue {}", r, g, b);
        }
        Message::Hello { id: id_label @ 3..=7 } => {
            println!("Found an id in range: {}", id_label);
        },
        Message::Hello { id: id_label@ i32::MIN..=2_i32 } | Message::Hello { id: id_label@ 8_i32..=i32::MAX } => {
            println!("Found an id out of range: {}", id_label);
        },
    }

    let msg = Message::Hello { id: 5 };
match msg {
    Message::Hello { id: id_variable @ 3..=7 } => {
        println!("Found an id in range: {}", id_variable);
    }
    Message::Hello { id: 10..=12 } => {
        println!("Found an id in another range");
    }
    Message::Hello { id } => {
        println!("Found some other id: {}", id);
    }
    _ => {}
}
}
//生成一个可失败的方法
fn plus_one_f(x: Option<i32>) -> Option<i32> {
    match x {
        None => None,
        Some(i) => Some(i + 1),
    }
}
//生成一个不可失败的方法
fn plus_one(x: Option<i32>) -> i32 {
    match x {
        None => 0,
        Some(i) => i + 1,
    }
}

enum Message {
    Hello { id: i32 },
    Quit,
    Move { x: i32, y: i32 },
    Write(String),
    ChangeColor(i32, i32, i32),
}

